package com.youedata.modular.controller;

import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youedata.base.pojo.page.LayuiPageFactory;
import com.youedata.base.tips.DCResponse;
import com.youedata.modular.entity.*;
import com.youedata.modular.enums.SuccessFlag;
import com.youedata.modular.model.dto.*;
import com.youedata.modular.service.*;
import com.youedata.util.FastDFSKit;
import com.youedata.util.ToolUtil;
import com.youedata.util.sdkUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 三方接口控制器
 *
 * @author hst
 * @date 2021-06-05 19:25:44
 */
@Controller
@Api(value = "/api", tags = "三方接口")
@RequestMapping("/api")
@Slf4j
public class APIController {

    @Autowired
    private FastDFSKit fastDFSKit;

    @Autowired
    private ILawNoticeInfoService lawNoticeInfoService;

    @Autowired
    private ILegalWorkersInfoService legalWorkersInfoService;

    @Autowired
    private ILegalServiceInfoService legalServiceInfoService;

    @Autowired
    private IJhTravelInfoService jhTravelInfoService;

    @Autowired
    private IWaterCutOffNoticeInfoService waterCutOffNoticeInfoService;

    @Autowired
    private IWaterMeterRepairInfoService waterMeterRepairInfoService;

    @Autowired
    private IEnterpriseWaterMeterRepairInfoService enterpriseWaterMeterRepairInfoService;

    @Value("${rest.GETINITCODE_URL}")
    private String getInitCodeUrl;

    @Value("${rest.GETAUTHCODE_URL}")
    private String getAuthCodeUrl;

    @Value("${rest.GETACCESSTOKEN_URL}")
    private String getAccessTokenUrl;

    @Value("${rest.REFRESHACCESSTOKEN_URL}")
    private String refreshAccessTokenUrl;

    @Value("${rest.CHECKACCESSTOKEN_URL}")
    private String checkAccessTokenUrl;

    @Value("${rest.CHECKREQUESTCODE_URL}")
    private String checkRequestCodeUrl;

    @Value("${rest.GETUSERINFO_URL}")
    private String getUserInfoUrl;

    @Autowired
    private IKeyInfoService keyInfoService;


    /**
     * 分页查询列表
     *
     * @author hst
     * @date 2021-07-12
     */
    @ResponseBody
    @GetMapping("/lawNoticeInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(LawNoticeInfoDTO lawNoticeInfoDto) {
        LawNoticeInfo lawNoticeInfo = new LawNoticeInfo();
        lawNoticeInfoDto.setNoticeTitle(StringUtils.isEmpty(lawNoticeInfoDto.getNoticeTitle()) ? null : lawNoticeInfoDto.getNoticeTitle());

        BeanUtils.copyProperties(lawNoticeInfoDto, lawNoticeInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();
        String title = lawNoticeInfo.getNoticeTitle();
        //根据条件查询
        //page.setRecords(this.lawNoticeInfoService.page(page, Wrappers.query(lawNoticeInfo)).getRecords());
        // page.setRecords(this.lawNoticeInfoService.querytitlefuzzy(page, title));
        List<LawNoticeInfo> lawNoticeInfoList = this.lawNoticeInfoService.querytitlefuzzy(page, title);
        if (ObjectUtils.isNotEmpty(lawNoticeInfoList)) {
            lawNoticeInfoList.stream().map(x -> {
                if (ToolUtil.isNotEmpty(x.getCreateTime())) {
                    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                    x.setCreateTimeStr(dtf.format(x.getCreateTime()));
                }
                return x;
            }).collect(Collectors.toList());
        }
        page.setRecords(lawNoticeInfoList);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 根据主键查询单条详情
     *
     * @author hst
     * @date 2021-07-12
     */
    @ResponseBody
    @PostMapping("/lawNoticeInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData detail(@RequestParam("id") String id) {
        // return ResponseData.success(this.lawNoticeInfoService.getById(id));
        LawNoticeInfo lawNoticeInfo = this.lawNoticeInfoService.getById(id);
        if (ToolUtil.isNotEmpty(lawNoticeInfo)) {
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            lawNoticeInfo.setCreateTimeStr(dtf.format(lawNoticeInfo.getCreateTime()));
        }
        return ResponseData.success(lawNoticeInfo);
    }

    @ResponseBody
    @GetMapping("/legalWorkersInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(LegalWorkersInfoDTO legalWorkersInfoDto) {
        LegalWorkersInfo legalWorkersInfo = new LegalWorkersInfo();

        // 过滤参数中的空字符串
        legalWorkersInfoDto.setName(StringUtils.isEmpty(legalWorkersInfoDto.getName()) ? null : legalWorkersInfoDto.getName());

        BeanUtils.copyProperties(legalWorkersInfoDto, legalWorkersInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        String name = legalWorkersInfo.getName();

        //根据条件查询
        //page.setRecords(this.legalWorkersInfoService.page(page, Wrappers.query(legalWorkersInfo)).getRecords());
        page.setRecords(this.legalWorkersInfoService.queryWorkersInfoFuzzy(page, name, legalWorkersInfo.getTag()));
        return LayuiPageFactory.createPageInfo(page);
    }

    @ResponseBody
    @PostMapping("/legalWorkersInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData legalWorkersInfoDetail(@RequestParam("id") String id) {
        return ResponseData.success(this.legalWorkersInfoService.getById(id));
    }

    @ResponseBody
    @GetMapping("/legalServiceInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(LegalServiceInfoDTO legalServiceInfoDto) {
        LegalServiceInfo legalServiceInfo = new LegalServiceInfo();

        // 过滤参数中的空字符串
        legalServiceInfoDto.setField(StringUtils.isEmpty(legalServiceInfoDto.getField()) ? null : legalServiceInfoDto.getField());
        legalServiceInfoDto.setClassify(StringUtils.isEmpty(legalServiceInfoDto.getClassify()) ? null : legalServiceInfoDto.getClassify());

        BeanUtils.copyProperties(legalServiceInfoDto, legalServiceInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        //根据条件查询
        //page.setRecords(this.legalServiceInfoService.page(page, Wrappers.query(legalServiceInfo)).getRecords());
        page.setRecords(this.legalServiceInfoService.queryLegalServiceInfoFuzzy(page, legalServiceInfo));

        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 根据主键查询单条详情
     *
     * @author qy
     * @date 2021-07-15
     */
    @ResponseBody
    @PostMapping("/legalServiceInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData legalServiceInfoDetail(@RequestParam("id") String id) {
        return ResponseData.success(this.legalServiceInfoService.getById(id));
    }

    /**
     * 分页查询列表
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @GetMapping("/jhTravelInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(JhTravelInfoDTO jhTravelInfoDto) {
        JhTravelInfo jhTravelInfo = new JhTravelInfo();

        //过滤空字符串
        jhTravelInfoDto.setName(StringUtils.isEmpty(jhTravelInfoDto.getName()) ? null : jhTravelInfoDto.getName());
        jhTravelInfoDto.setType(StringUtils.isEmpty(jhTravelInfoDto.getType()) ? null : jhTravelInfoDto.getType());

        BeanUtils.copyProperties(jhTravelInfoDto, jhTravelInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        String name = jhTravelInfo.getName();
        String type = jhTravelInfo.getType();

        //根据条件查询
        // page.setRecords(this.jhTravelInfoService.page(page, Wrappers.query(jhTravelInfo)).getRecords());
        page.setRecords(this.jhTravelInfoService.queryNameFuzzy(page, name, type));

        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 根据主键查询单条详情
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/jhTravelInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData jhTravelInfoDetail(@RequestParam("id") String id, @RequestParam("countFlag") String countFlag) {

        return ResponseData.success(this.jhTravelInfoService.detailById(id, countFlag));
    }

    /**
     * 浏览量自增
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/viewCount")
    @ApiOperation(value = "浏览量自增")
    public ResponseData viewCount(@RequestParam("id") String id) {
//        int ori_consume=Integer.parseInt(this.jhTravelInfoService.getById(id).getConsume());
//        ori_consume++;
//        System.out.println(ori_consume);
//        this.jhTravelInfoService.getById(id).setConsume(Integer.toString(ori_consume));
//        jdbcTemplate.update("update jh_travel_info set consume=consume+1 where id =?", id);
//        return ResponseData.success(this.jhTravelInfoService.getById(id).getConsume());
        return null;
    }

    /**
     * 根据主键查询单条详情
     *
     * @author hst
     * @date 2021-07-26
     */
    @ResponseBody
    @PostMapping("/waterCutOffNoticeInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData waterCutOffNoticeInfoDetail(@RequestParam("id") String id) {
        WaterCutOffNoticeInfo waterCutOffNoticeInfo = this.waterCutOffNoticeInfoService.getById(id);
        if (ToolUtil.isNotEmpty(waterCutOffNoticeInfo)) {
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            waterCutOffNoticeInfo.setCreateTimeStr(dtf.format(waterCutOffNoticeInfo.getCreateTime()));
        }
        return ResponseData.success(waterCutOffNoticeInfo);
    }

    /**
     * 分页查询列表
     *
     * @author hst
     * @date 2021-07-26
     */
    @ResponseBody
    @GetMapping("/waterCutOffNoticeInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(WaterCutOffNoticeInfoDTO waterCutOffNoticeInfoDto) {
        WaterCutOffNoticeInfo waterCutOffNoticeInfo = new WaterCutOffNoticeInfo();

        waterCutOffNoticeInfoDto.setType(StringUtils.isEmpty(waterCutOffNoticeInfoDto.getType()) ? null : waterCutOffNoticeInfoDto.getType());

        BeanUtils.copyProperties(waterCutOffNoticeInfoDto, waterCutOffNoticeInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        String type = waterCutOffNoticeInfoDto.getType();
        //根据条件查询
        //page.setRecords(this.waterCutOffNoticeInfoService.page(page, Wrappers.query(waterCutOffNoticeInfo)).getRecords());
        List<WaterCutOffNoticeInfo> waterCutOffNoticeInfoList = this.waterCutOffNoticeInfoService.queryTypeFuzzy(page, type);
        if (ObjectUtils.isNotEmpty(waterCutOffNoticeInfoList)) {
            waterCutOffNoticeInfoList.stream().map(x -> {
                if (ToolUtil.isNotEmpty(x.getCreateTime())) {
                    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                    x.setCreateTimeStr(dtf.format(x.getCreateTime()));
                }
                return x;
            }).collect(Collectors.toList());
        }
        page.setRecords(waterCutOffNoticeInfoList);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 水表报修根据主键查询单条详情
     *
     * @author hst
     * @date 2021-07-26
     */
    @ResponseBody
    @PostMapping("/waterMeterRepairInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData waterMeterRepairInfoDetail(@RequestParam("id") String id) {
        //return ResponseData.success(this.waterMeterRepairInfoService.getById(id));
        WaterMeterRepairInfo waterMeterRepairInfo = this.waterMeterRepairInfoService.getById(id);
        if (ToolUtil.isNotEmpty(waterMeterRepairInfo)) {
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            waterMeterRepairInfo.setCreateTimeStr(dtf.format(waterMeterRepairInfo.getCreateTime()));
        }
        return ResponseData.success(waterMeterRepairInfo);
    }

    /**
     * 水表报修分页查询列表
     *
     * @author hst
     * @date 2021-07-26
     */
    @ResponseBody
    @GetMapping("/waterMeterRepairInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(WaterMeterRepairInfoDTO waterMeterRepairInfoDto) {
        WaterMeterRepairInfo waterMeterRepairInfo = new WaterMeterRepairInfo();

        //过滤空字符串
        waterMeterRepairInfoDto.setName(StringUtils.isEmpty(waterMeterRepairInfoDto.getName()) ? null : waterMeterRepairInfoDto.getName());
        waterMeterRepairInfoDto.setTag(StringUtils.isEmpty(waterMeterRepairInfoDto.getTag()) ? null : waterMeterRepairInfoDto.getTag());

        BeanUtils.copyProperties(waterMeterRepairInfoDto, waterMeterRepairInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        //根据条件查询
        //page.setRecords(this.waterMeterRepairInfoService.page(page, Wrappers.query(waterMeterRepairInfo)).getRecords());
        // page.setRecords(this.waterMeterRepairInfoService.queryFuzzySearch(page, waterMeterRepairInfo));
        List<WaterMeterRepairInfo> waterMeterRepairInfoList = this.waterMeterRepairInfoService.queryFuzzySearch(page, waterMeterRepairInfo);
        if (ObjectUtils.isNotEmpty(waterMeterRepairInfoList)) {
            waterMeterRepairInfoList.stream().map(x -> {
                if (ToolUtil.isNotEmpty(x.getCreateTime())) {
                    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                    x.setCreateTimeStr(dtf.format(x.getCreateTime()));
                }
                return x;
            }).collect(Collectors.toList());
        }
        page.setRecords(waterMeterRepairInfoList);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 企业水表报修根据主键查询单条详情
     *
     * @author hst
     * @date 2021-08-13
     */
    @ResponseBody
    @PostMapping("/enterpriseWaterMeterRepairInfo/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData enterpriseWaterMeterRepairInfoDetail(@RequestParam("id") String id) {
        return ResponseData.success(this.enterpriseWaterMeterRepairInfoService.getById(id));
    }

    /**
     * 企业水表报修分页查询列表
     *
     * @author hst
     * @date 2021-08-13
     */
    @ResponseBody
    @GetMapping("/enterpriseWaterMeterRepairInfo/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(EnterpriseWaterMeterRepairInfoDTO enterpriseWaterMeterRepairInfoDto) {
        EnterpriseWaterMeterRepairInfo enterpriseWaterMeterRepairInfo = new EnterpriseWaterMeterRepairInfo();

        //过滤空字符串
        enterpriseWaterMeterRepairInfoDto.setName(StringUtils.isEmpty(enterpriseWaterMeterRepairInfoDto.getName()) ? null : enterpriseWaterMeterRepairInfoDto.getName());
        enterpriseWaterMeterRepairInfoDto.setTag(StringUtils.isEmpty(enterpriseWaterMeterRepairInfoDto.getTag()) ? null : enterpriseWaterMeterRepairInfoDto.getTag());

        BeanUtils.copyProperties(enterpriseWaterMeterRepairInfoDto, enterpriseWaterMeterRepairInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        //根据条件查询
        //page.setRecords(this.enterpriseWaterMeterRepairInfoService.page(page, Wrappers.query(enterpriseWaterMeterRepairInfo)).getRecords());
        page.setRecords(this.enterpriseWaterMeterRepairInfoService.queryFuzzySearch(page, enterpriseWaterMeterRepairInfo));
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 企业水表报修前端提交
     *
     * @author hst
     * @date 2021-08-13
     */
    @ResponseBody
    @PostMapping("/enterpriseWaterMeterRepairInfo/addItem")
    @ApiOperation(value = "前端提交")
    public DCResponse<Void> addItem(EnterpriseWaterMeterRepairInfoDTO enterpriseWaterMeterRepairInfoDto) {
        EnterpriseWaterMeterRepairInfo enterpriseWaterMeterRepairInfo = new EnterpriseWaterMeterRepairInfo();
        BeanUtils.copyProperties(enterpriseWaterMeterRepairInfoDto, enterpriseWaterMeterRepairInfo);
//        enterpriseWaterMeterRepairInfo.setCreateUser(UserHolder.getUserId());
        enterpriseWaterMeterRepairInfo.setCreateTime(LocalDateTime.now());
        this.enterpriseWaterMeterRepairInfoService.save(enterpriseWaterMeterRepairInfo);
        return DCResponse.ok(null);
    }

    /**
     * 上传文件
     *
     * @author hao.yan
     * @date 2020-07-30
     */
    @ResponseBody
    @PostMapping("/fastDFS/upload")
    @ApiOperation(value = "上传并返回完整访问地址")
    public ResponseData upload(MultipartFile file) throws IOException {
        return ResponseData.success(fastDFSKit.uploadFile(file));
    }

    /**
     * 水表报修新增
     *
     * @author hst
     * @date 2021-07-26
     */
    @ResponseBody
    @PostMapping("/waterMeterRepairInfo/addItem")
    @ApiOperation(value = "前端提交接口")
    public DCResponse<Void> addItem(WaterMeterRepairInfoDTO waterMeterRepairInfoDto) {
        WaterMeterRepairInfo waterMeterRepairInfo = new WaterMeterRepairInfo();
        BeanUtils.copyProperties(waterMeterRepairInfoDto, waterMeterRepairInfo);
//        waterMeterRepairInfo.setCreateUser(String.valueOf(UserHolder.getUserId()));
        waterMeterRepairInfo.setCreateTime(LocalDateTime.now());
        this.waterMeterRepairInfoService.save(waterMeterRepairInfo);
        return DCResponse.ok(null);
    }

    /**
     * 上传指定尺寸缩略图
     *
     * @author hao.yan
     * @date 2020-07-30
     */
    @ResponseBody
    @PostMapping("/uploadImageThumbnail")
    @ApiOperation(value = "上传图片且生成缩略图并返回完整访问地址")
    public ResponseData uploadImageThumbnail(MultipartFile file, int width, int height) throws IOException {
        return ResponseData.success(fastDFSKit.uploadImageThumbnail(file, width, height));
    }

    /**
     * 获取initCode
     *
     * @author hao.yan
     * @date 2020-07-30
     */
    @ResponseBody
    @GetMapping("/getInitCode/{keyId}")
    @ApiOperation(value = "获取initCode")
    public ResponseData getInitCode(@PathVariable Integer keyId) {
        ResponseData responseData = null;

        KeyInfo keyInfo = keyInfoService.getById(keyId);
        if (ToolUtil.isEmpty(keyInfo)) {
            return ResponseData.error("查询不到key值！");
        }

        String resultJson = sdkUtil.getInitCode(getInitCodeUrl, keyInfo.getAppId(), keyInfo.getAppKey());
        if (resultJson != null) {
            Map resultMap = JSON.parseObject(resultJson, Map.class);
            if (SuccessFlag.SUCCESS.getCode().equals(resultMap.get("code"))) {
                responseData = ResponseData.success(resultMap.get("data"));
            } else {
                log.error(resultMap.get("msg").toString());
                responseData = ResponseData.error(resultMap.get("msg").toString());
            }
        }
        return responseData;
    }


    /**
     * 校验RequestCode
     *
     * @author hao.yan
     * @date 2020-07-30
     */
    @ResponseBody
    @PostMapping("/checkRequestCode")
    @ApiOperation(value = "校验RequestCode")
    public ResponseData checkRequestCode(@RequestBody CheckRequestCodeDTO requestCodeDTO) {
        ResponseData responseData = null;

        String authCode = null;
        String accessToken = null;

        KeyInfo keyInfo = keyInfoService.getById(requestCodeDTO.getKeyId());
        if (ToolUtil.isEmpty(keyInfo)) {
            return ResponseData.error("查询不到key值！");
        }


        //获取authCode
        String authCodeJson = sdkUtil.getAuthCode(getAuthCodeUrl, requestCodeDTO.getAppId(), keyInfo.getAppKey());
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(authCodeJson)) {
            Map resultMap = JSON.parseObject(authCodeJson, Map.class);
            if (SuccessFlag.SUCCESS.getCode().equals(resultMap.get("code"))) {
                authCode = JSON.parseObject(resultMap.get("data").toString()).getString("authCode");
                log.info("authcode=========>{}", authCode);
            } else {
                log.error(resultMap.get("msg").toString());
                return ResponseData.error(resultMap.get("msg").toString());
            }
        }

        //获取accesToken
        String accesTokenJson = sdkUtil.getAccessToken(getAccessTokenUrl, requestCodeDTO.getAppId(), authCode);
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(accesTokenJson)) {
            Map resultMap = JSON.parseObject(accesTokenJson, Map.class);
            if (SuccessFlag.SUCCESS.getCode().equals(resultMap.get("code"))) {
                accessToken = JSON.parseObject(resultMap.get("data").toString()).getString("accessToken");
                log.info("accessToken=========>{}", accessToken);
            } else {
                log.error(resultMap.get("msg").toString());
                return ResponseData.error(resultMap.get("msg").toString());
            }
        }

        //校验RequestCode
        String resultJson = sdkUtil.checkRequestCode(checkRequestCodeUrl, requestCodeDTO.getAppId(), accessToken, requestCodeDTO.getRequestCode());
        if (resultJson != null) {
            Map resultMap = JSON.parseObject(resultJson, Map.class);
            if (SuccessFlag.SUCCESS.getCode().equals(resultMap.get("code"))) {
                responseData = ResponseData.success(resultMap.get("data"));
            } else {
                responseData = ResponseData.error(resultMap.get("msg").toString());
            }
        }
        return responseData;
    }

    /**
     * 获取用户信息
     *
     * @author hao.yan
     * @date 2020-07-30
     */
    @ResponseBody
    @PostMapping("/getUserInfo")
    @ApiOperation(value = "获取用户信息")
    public ResponseData getUserByUserAccessToken(@RequestBody GetUserInfoDTO userInfoDTO) {
        ResponseData responseData;
        UserInfoByOpenidDTO userInfoByOpenidDTO = sdkUtil.getUserByUserAccessToken(getUserInfoUrl, userInfoDTO);

        if (ToolUtil.isEmpty(userInfoByOpenidDTO)) {
            log.error("获取用户信息失败！");
            responseData = ResponseData.error("获取用户信息失败！");
        } else {
            responseData = ResponseData.success(userInfoByOpenidDTO);
        }
        return responseData;
    }
}
